<?php

require_once dirname(__FILE__).'/../class/functions.php';
require_once dirname(__FILE__).'/../class/user.class.php';

$a = session_id();if(empty($a)) session_start();
$realizat='';
$logat = is_logat();
$adm=0;
if($logat == 0)
    die("Nu v-ati logat");
else
{
    if( $_SESSION['logat'] == "admin" )
    {
        //echo "sunteti admin";     
        $user=unserialize($_SESSION['userc']);
        //echo list_rez();
        //$admin=1;
        $adm=1;
    }
    else die("Interzis utilizatorilor normali!(Nu aveti drepturi!)");
    
}


if(isset($_POST['Submit'])) {
   mysql_safer(); 
   $fid=intval($_GET['id']); 
     foreach($_POST['meta'] as $meta)
           if(isset($meta)&&strlen($meta)>3)
                         $db->q("CALL meta_in('".$meta."',".$fid.")");
   $query="UPDATE  `file_table` SET  `nume` =  '".$_POST['nume']."',
                                     `descriere` =  '".$_POST['descriere']."',
                                     `CAT` =  '".$_POST['categoria']."',
                                     `AN` =  '".$_POST['anul']."',
                                     `UID` = '".$_POST['uploader']."',    
                                     `status` =  '".$_POST['activat']."' WHERE  `FID` ='".$fid."';";
   
   $db->q($query);
   $realizat = "<br/> Update realizat cu succes! <br/> ";
   $realizat.='<script src="/netbeans/proiect-licentza/js/jquery.min_1.js" type="text/javascript"></script> <script type="text/javascript"> setTimeout(function(){window.close()},4000);</script>';
}



if(isset($_GET['id'])&&$adm){
 mysql_safer();   
 $fid=intval($_GET['id']); 
   $sql_cauta="SELECT * FROM `file_table` WHERE FID=$fid";
   $rezultat = $db->q($sql_cauta);
   $row = mysql_fetch_array($rezultat);
   $uidu=$row['UID']; $descriere=$row['descriere']; $activat=$row['status'];
 
 ?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']."?id=$fid"; ?>">
<?
   
 echo pt_rezervari("categorii", "categoria",$row['CAT']);
 echo pt_rezervari("ani", "anul",$row['AN']); 
 
 



?>
<input type="text" name="nume" value="<? echo $row['nume'];?>"/>
<select name="uploader"  >
            <option value=""></option>
            <?
            $sql_select_utiliz="Select ID, username from utilizatori";
            $result = $db->q($sql_select_utiliz);
            while($row = mysql_fetch_array($result))
            {echo "<option value=$row[0]"; if($uidu==$row[0]) echo " selected ";  echo ">$row[1]</option>";}
                    
            ?>
</select>
<select name="activat">
        <option value='0'>Inactiv </option>
        <option value='1' <? if($activat) echo " selected "?>>Activ </option>
</select>
<br>
<textarea rows="3" cols="20" name="descriere" style="border: solid lightgrey;margin-top: 10px;float: left;width:550px;"> <? echo $descriere;?>   </textarea>        <br/>                                                       <br/>
                                                                                       <br/> <h3> Etichete: <?echo list_meta($fid,1); ?></h3>
                        <input type="text" name="meta[]" value="">   <input type="text" name="meta[]" value="">  <input type="text" name="meta[]" value="">  <br/>
                        <input type="text" name="meta[]" value="">   <input type="text" name="meta[]" value="">  <input type="text" name="meta[]" value="">  <br/>
                        <a href="#" class="grey-button pcb"><span><input  type="submit" name="Submit" value="Submit"></span></a>
                        
</form>                       
                        
                     

   <? }
        echo $realizat;                ?>